]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
cleanup: Avoid implicit coercion
authorFlorian Müllner <fmuellner@gnome.org>
Tue, 29 Jan 2019 23:01:21 +0000 (00:01 +0100)
committerFlorian Müllner <fmuellner@gnome.org>
Mon, 1 Jul 2019 21:44:11 +0000 (23:44 +0200)
Converting a variable to a particular type can be done explicitly (with
functions like Number() or toString()) or implicitly by relying on type
coercion (like concatenating a variable to the empty string to force
a string, or multiplying it with 1 to force a number).

As those tend to be less readable and clear, they are best avoided. So
replace the cases of string coercion we use with template strings, and
clarify the places that can be confused with number coercion.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/607

js/ui/barLevel.js
js/ui/extensionSystem.js
js/ui/lookingGlass.js
js/ui/main.js
js/ui/shellDBus.js
js/ui/slider.js

index c4072e2cf83338e69798ba92a519e51bb95dbd75..d2f961ce2e09a2235fa14834c81d5890ba399e3f 100644 (file)
@@ -105,7 +105,7 @@ var BarLevel = class {
             overdriveSeparatorWidth = themeNode.get_length('-barlevel-overdrive-separator-width');
 
         /* background bar */
-        cr.arc(width - barLevelBorderRadius - barLevelBorderWidth, height / 2, barLevelBorderRadius, TAU * 3 / 4, TAU * 1 / 4);
+        cr.arc(width - barLevelBorderRadius - barLevelBorderWidth, height / 2, barLevelBorderRadius, TAU * (3 / 4), TAU * (1 / 4));
         cr.lineTo(endX, (height + barLevelHeight) / 2);
         cr.lineTo(endX, (height - barLevelHeight) / 2);
         cr.lineTo(width - barLevelBorderRadius - barLevelBorderWidth, (height - barLevelHeight) / 2);
@@ -117,7 +117,7 @@ var BarLevel = class {
 
         /* normal progress bar */
         let x = Math.min(endX, overdriveSeparatorX - overdriveSeparatorWidth / 2);
-        cr.arc(barLevelBorderRadius + barLevelBorderWidth, height / 2, barLevelBorderRadius, TAU * 1 / 4, TAU * 3 / 4);
+        cr.arc(barLevelBorderRadius + barLevelBorderWidth, height / 2, barLevelBorderRadius, TAU * (1 / 4), TAU * (3 / 4));
         cr.lineTo(x, (height - barLevelHeight) / 2);
         cr.lineTo(x, (height + barLevelHeight) / 2);
         cr.lineTo(barLevelBorderRadius + barLevelBorderWidth, (height + barLevelHeight) / 2);
@@ -149,7 +149,7 @@ var BarLevel = class {
               Clutter.cairo_set_source_color(cr, barLevelActiveColor);
           else
               Clutter.cairo_set_source_color(cr, barLevelOverdriveColor);
-          cr.arc(endX, height / 2, barLevelBorderRadius, TAU * 3 / 4, TAU * 1 / 4);
+          cr.arc(endX, height / 2, barLevelBorderRadius, TAU * (3 / 4), TAU * (1 / 4));
           cr.lineTo(Math.floor(endX), (height + barLevelHeight) / 2);
           cr.lineTo(Math.floor(endX), (height - barLevelHeight) / 2);
           cr.lineTo(endX, (height - barLevelHeight) / 2);
index 744f5e7ac193cd84a3b6e1b87a6fd4eae234794b..a53838d587fe5284b22da54e7f768420ad8bfc7c 100644 (file)
@@ -147,7 +147,7 @@ function logExtensionError(uuid, error) {
     if (!extension)
         return;
 
-    let message = '' + error;
+    let message = `${error}`;
 
     extension.state = ExtensionState.ERROR;
     if (!extension.errors)
index 3149cf4212e99280af182c046c5bb30c00457049..edcfdecc8b0f0b125df8fb5c0d05a8da3f781f17 100644 (file)
@@ -242,7 +242,7 @@ function objectToString(o) {
         // special case this since the default is way, way too verbose
         return '<js function>';
     } else {
-        return '' + o;
+        return `${o}`;
     }
 }
 
index abd83721c0b985ace442510481e2dcd00a03353e..ea0a93984fa9f71444ffa6c7eb802bb4ad69b70f 100644 (file)
@@ -658,7 +658,7 @@ function _queueBeforeRedraw(workId) {
  */
 function initializeDeferredWork(actor, callback, props) {
     // Turn into a string so we can use as an object property
-    let workId = '' + (++_deferredWorkSequence);
+    let workId = `${(++_deferredWorkSequence)}`;
     _deferredWorkData[workId] = { 'actor': actor,
                                   'callback': callback };
     actor.connect('notify::mapped', () => {
index 19d07acce619f74734e89a24a2ddd94772ec81ec..a9224f8417c3844ff0ec027330cae9fb9ba6a1be 100644 (file)
@@ -65,7 +65,7 @@ var GnomeShell = class {
                 returnValue = '';
             success = true;
         } catch (e) {
-            returnValue = '' + e;
+            returnValue = `${e}`;
             success = false;
         }
         return [success, returnValue];
index 3c1b35e05ea2173dc44b9f02b2a97e265fdf491c..4025a11fd3edc20c57ab3f4cc3f8df72bfa8dfc7 100644 (file)
@@ -142,7 +142,7 @@ var Slider = class extends BarLevel.BarLevel {
         if (direction == Clutter.ScrollDirection.DOWN) {
             delta = -SLIDER_SCROLL_STEP;
         } else if (direction == Clutter.ScrollDirection.UP) {
-            delta = +SLIDER_SCROLL_STEP;
+            delta = SLIDER_SCROLL_STEP;
         } else if (direction == Clutter.ScrollDirection.SMOOTH) {
             let [dx, dy] = event.get_scroll_delta();
             // Even though the slider is horizontal, use dy to match